<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /**
     * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
     * 思路：https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/solution/javascript-shan-xiuchu-gaipai-xu-shu-zu-zhong-de-z/
     */
    const arr = [1, 1, 2, 2, 3];

    function removeDuplicates(nums) {
      let len = 1;
      for (let i = 1; i < nums.length; i++)
        if (nums[i] !== nums[i-1]) nums[len++] = nums[i];
      return len;
    }

    console.log(removeDuplicates(arr));
  </script>
</body>
</html>